﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApplication2.ViewModels;
using System.Security;
using WpfApplication2.SindicatoWebService;
using WpfApplication2.Helpers;
using System.Globalization;
using WpfApplication2.Views.Usuario;


namespace WpfApplication2.Views
{
    /// <summary>
    /// Interaction logic for Login.xaml
    /// </summary>
    public partial class Login : Page
    {
        public SindicatoWebService.Service1SoapClient WS;

        public string Password
        {
            get { return pswContraseña.Password; }
        }

        public string User
        {
            get { return txtNombreUsuario.Text; }
        }

        public Login()
        {
            InitializeComponent();
            WS = new SindicatoWebService.Service1SoapClient();
            txtNombreUsuario.Focus();
        }

        private void btnIngresar_Click(object sender, RoutedEventArgs e)
        {
            NavigationService ns = NavigationService.GetNavigationService(this);


            UsuarioDTO Usuario = WS.GetUsuario(User, Password);


            if (string.IsNullOrEmpty(Usuario.UserName))
            {
                lblErrorMessage.Visibility = Visibility.Visible;
            }
            else
            {
                ns.Navigate(new MainWindow(Usuario));
            }

            
        }

        private ERoles ObtenerRol(string User, string Password)
        {
            return ERoles.Jefe;
        }

        private void CheckEnter(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Enter)
            {
                return;
            }
            btnIngresar_Click(this, e);
        }
    }
}
